package com.ruoyi.web.controller.fund;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.costQuery.domain.HouseCostT;
import com.ruoyi.refund.domain.HouseRefundT;
import com.ruoyi.refund.service.IHouseRefundTService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.refundQuery.service.IHouseRefundQueryTService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退款查询Controller
 * 
 * @author lijie
 * @date 2023-05-04
 */
@RestController
@RequestMapping("/fund/refundQuery")
public class HouseRefundQueryTController extends BaseController
{
    @Autowired
    private IHouseRefundQueryTService houseRefundTService;
    @Autowired
    private IHouseRefundTService houseRefundTService1;

    /**
     * 查询退款查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseRefundT houseRefundT)
    {
        startPage();
        List<HouseRefundT> list = houseRefundTService.selectHouseRefundTList(houseRefundT);
        if(getDataTableSumJudge(list)){
            HouseRefundT houseRefundVO = houseRefundTService.selectHouseRefundSum(houseRefundT);
            houseRefundVO.setAreaName("合计");
            list.add(houseRefundVO);
        }
        return getDataTable(list);
    }

    /**
     * 导出退款查询列表
     */
    @Log(title = "退款查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseRefundT houseRefundT)
    {
        List<HouseRefundT> list = houseRefundTService.selectHouseRefundTList(houseRefundT);
        if(getDataTableSumJudge(list)){
            HouseRefundT houseRefundVO = houseRefundTService.selectHouseRefundSum(houseRefundT);
            houseRefundVO.setAreaName("合计");
            list.add(houseRefundVO);
        }
        ExcelUtil<HouseRefundT> util = new ExcelUtil<HouseRefundT>(HouseRefundT.class);
        util.exportExcel(response, list, "退款查询数据");
    }

    /**
     * 获取退款查询详细信息
     */
    @GetMapping(value = "/{refundId}")
    public AjaxResult getInfo(@PathVariable("refundId") Long refundId)
    {
        return AjaxResult.success(houseRefundTService.selectHouseRefundTByRefundId(refundId));
    }

    /**
     * 新增退款查询
     */
    @Log(title = "退款查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseRefundT houseRefundT)
    {
        return toAjax(houseRefundTService.insertHouseRefundT(houseRefundT));
    }

    /**
     * 修改退款查询
     */
    @Log(title = "退款查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseRefundT houseRefundT)
    {
        return toAjax(houseRefundTService.updateHouseRefundT(houseRefundT));
    }

    /**
     * 删除退款查询
     */
    @Log(title = "退款查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{refundIds}")
    public AjaxResult remove(@PathVariable Long[] refundIds)
    {
        return toAjax(houseRefundTService.deleteHouseRefundTByRefundIds(refundIds));
    }

    @GetMapping(value = "/getNote/{costId}")
    public AjaxResult getNote(@PathVariable("costId") Long costId)
    {
        HouseRefundT houseRefundVO = houseRefundTService1.selectHouseRefundNote(costId);
        return AjaxResult.success(houseRefundVO);
    }
}
